import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2022-09-07
 * Time: 21:43
 */
public class Test_0905 {


    //三步旋转法
    public static void reverse(int [] nums ,int left , int right ){
        while(left<right){
            int tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
            left+=1;
            right-=1;
        }
    }

    public static void rotate2(int [] nums ,int k){
        k%=nums.length;
        int len = nums.length;
        reverse(nums,0,len-1);
        reverse(nums,0,k-1);
        reverse(nums,k,len-1);
    }



    //交替旋转法
    public static void rotate1(int [] nums ,int k){
        int len = nums.length;
        k = k%len;
        int tmp = 0;
        for (int j = 0; j < len-k; j++) {
            for (int i = 0; i < len-1; i++) {
                tmp = nums[i];
                nums[i] = nums[i+1];
                nums[i+1] = tmp;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        Scanner scanner = new Scanner(System.in);
        int k =scanner.nextInt();
        rotate1(arr,k);
        int[] arr1 = {1,9,8,6,4,5,6,7};
        rotate2(arr1,2);
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(arr1));

    }


    //数组nums包含从0到n的所有整数，但其中缺了一个

    //按位异或
    public static int missingNumber(int [] nums){
        int x = 0;
        for (int i = 1; i <= nums.length ; i++) {
            x ^= i;
        }
        for (int i = 0; i < nums.length; i++) {
            x^=nums[i];
        }
        return x;
    }

    //求和做差
    public static int missingNumber1(int [] nums){
        int ret = 0;
        //参数数组总和
        for (int i = 0; i <nums.length ; i++) {
            ret+= nums[i];
        }
        //完整数组总和
        int add = 0;
        for (int i = 1; i <=nums.length ; i++) {
            add+=i;
        }
        return add-ret;
    }
    public static void main1(String[] args) {
        int [] array = {1,3,4,0};
        int ret = missingNumber(array);
        System.out.println(ret);

        int ret1 = missingNumber1(array);
        System.out.println(ret1);
        int ret3 = array.length;
    }
}
